package com.ydgk.jishuzhan.service.impl;

import com.ydgk.jishuzhan.beans.Talk;
import com.ydgk.jishuzhan.dao.TalkMapper;
import com.ydgk.jishuzhan.dao.UserMapper;
import com.ydgk.jishuzhan.service.TalkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TalkServiceImpl implements TalkService {

    @Autowired
    private TalkMapper talkMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Talk> findTalks() {
        List<Talk> talks = talkMapper.findAll();
        List<Talk> talks1=new ArrayList<>();
        for (Talk talk:talks){
            talk.getTalkInfo().setUser(userMapper.findUserById(talk.getUserId()));
            talks1.add(talk);
        }
        return talks1;
    }

    @Override
    public void save(Talk talk) {
        talkMapper.save(talk);
    }

    @Override
    public Talk findById(Integer id) {
        return talkMapper.findById(id);
    }

    @Override
    public List<Talk> findTalksById(Integer id) {
        return talkMapper.findTalkById(id);
    }
}
